package com.atguigu.day14.test10;

import java.util.Scanner;

/**
 * @author fenge
 */
public class Test10{
    public static void main(String[] args) {
        System.out.print("原数字：");
        Handleable h1= new Handleable() {
            @Override
            public String handleString(String num) {
                int dot = num.indexOf(".");
                num = num.substring(0,dot);
                return num;
            }
        };
        Scanner s = new Scanner(System.in);
        String str1 = s.next();

        System.out.println("取整后："+h1.handleString(str1));
        System.out.print("原数字：");
        String str2 = s.next();
        System.out.print("保留");
        int some = s.nextInt();
        System.out.println("位小数，四舍五入后：");
        Handleable h2 = new Handleable() {
            @Override
            public String handleString(String num) {
                int dot = num.indexOf(".");
                int nee = dot+some;

                char rea = num.charAt(nee);
                num = num.substring(0,nee);
                if (rea>='5')
                    rea++;
                num+=rea;
                return num;
            }
        };
        System.out.println(h2.handleString(str2));

    }
}
